package cn.bdqn.tools;

import cn.bdqn.pojo.BackendUser;
import cn.bdqn.pojo.DevUser;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class Handle extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        BackendUser backendUser = (BackendUser) request.getSession().getAttribute("backendUser");
        DevUser devUser = (DevUser) request.getSession().getAttribute("devUser");
        if (null != backendUser) {
            return true;
        } else if (null != devUser) {
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"/jsp/403.jsp");
            return false;
        }
    }

    //拦截器
/*    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException {
        BackendUser backendUser = (BackendUser) session.getAttribute("backendUser");
        DevUser devUser = (DevUser) session.getAttribute("devUser");
        if (null != backendUser) {
            return true;
        } else if (null != devUser) {
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"403.jsp");
            return false;
        }
    }*/
}
